home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: link-1.ts.bcc.ac.uk!ucecb09
- From: ucecb09@ucl.ac.uk (Robert Byrne)
- Subject: Re: C++ complex numbers slow as molasses?
- Message-ID: <1996Apr18.094043.62430@ucl.ac.uk>
- Date: Thu, 18 Apr 1996 09:40:43 GMT
- References: <4k6k8c$8h4@nyx.cs.du.edu> <9604071851.AA001o1@lorelei.demon.co.uk> <4ke5ap$b8b@mag1.magmacom.com> <Pine.LNX.3.91.960412073943.308E-100000@quoin1.quoininc.com> <4ktki7$vft@mag1.magmacom.com>
- Organization: University College London
-
- ezust@mag1.magmacom.com (Acme Instant Dehydrated Boulder Kit) writes:
- >Jean Pierre LeJacq <jplejacq@quoininc.com> wrote:
- >>
- >>class complex {
- >> public:
- >> complex & operator +=(complex const & lhs);
- >>};
-
- >The choices are:
- >If you use the +=, you must first initialize the destination explicitly, and
- >then call it twice to achieve the same functionality as one call to the
- >binary operator+
-
- Two calls?
- complex res = lhs;
- res += rhs;
- I can't see why two calls would be necessary unless you envision
- complex res = 0;
- res += lhs;
- res += rhs;
- for which I see no obvious advantage.
-
- >But if one is really concerned about runtime efficiency, chances are that a
- >2-operand member function add can be written so it is more efficient than
- >the operator+= used in the way described above.
-
- Can someone demonstrate this? Personally I can't see it happening for a
- class like complex even if the compiler elides the cp ctor for code
- such as
-
- complex operator+(const complex &lhs, const complex &rhs)
- {
- return complex(lhs) += rhs;
- }
-
- The binary operator+ is still not going to be as efficient as the
- assignment version. Although I would be pleased to see this disproved.
-
- Rob
-
- --
- Robert Byrne `I think therefore I am' says rather more than
- ucecb09@ucl.ac.uk is strictly certain.' -Bertrand Russell
-
-